package com.gxa.meiye.admin.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxa.meiye.admin.mapper.UpLoadImgurlMapper;
import com.gxa.meiye.admin.service.FileUpLoadService;
import com.gxa.meiye.admin.thread.UserThreadLocal;
import com.gxa.meiye.admin.utils.QCloudCosUtils;

import com.gxa.meiye.core.pojo.vo.TherapistLoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import com.gxa.meiye.admin.thread.UserThreadLocal;
import java.io.File;
@Service
public class FileUpLoadServiceImpl implements FileUpLoadService {
    @Autowired
    QCloudCosUtils qCloudCosUtils;
    @Autowired
    UpLoadImgurlMapper upLoadImgurlMapper;
    @Override
    public String upload(MultipartFile multipartFile) throws JsonProcessingException {
        String upload = qCloudCosUtils.upload(multipartFile);
        //修改头像的方法
        TherapistLoginInfo therapistLoginInfo = new TherapistLoginInfo();
        ObjectMapper objectMapper = new ObjectMapper();
         Object o = UserThreadLocal.get();
        therapistLoginInfo = objectMapper.readValue(o.toString(),TherapistLoginInfo.class);
        String phone = therapistLoginInfo.getPhone();
        upLoadImgurlMapper.updateImgurl(upload,phone);
        return upload;

    }

    @Override
    public String upload(File file) {
        return qCloudCosUtils.upload(file);
    }

}
